package com.zhy.deploy.websocket;

import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;

@Component
@ServerEndpoint(value = "/logServer",configurator = WebsocketConfigurator.class)
public class LogWebSocketServer {

    @OnOpen
    public void onOpen(Session session, EndpointConfig config) throws IOException {
        HttpSession httpSession = (javax.servlet.http.HttpSession) config.getUserProperties().get(HttpSession.class.getName());
        SessionContext.getInstance().AddSession(httpSession.getId(),session);
        session.getBasicRemote().sendText("start");
    }

    @OnClose
    public void onClose(Session session, CloseReason reason) {

    }

    @OnMessage
    public void onMessage(String message, Session session) {

    }

    @OnError
    public void onError(Session session, Throwable error) {
        error.printStackTrace();
    }

}
